package com.mynetwork.utils;

import java.util.Calendar;

import android.content.*;

/**
 * @brief	프레프런스 설정관련 도우미 클래스
 * @author  PiaJang
 */
public class SharedPrefHelper {
	
	public final static String INI_FILENAME_CONFIG = "config";
	
	//update time
	public final static String PRODUCT_LIST_UPDATE_TIME = "product_list_update_time";
	public final static String CONTENT_INFO_LIST_UPDATE_TIME = "content_info_list_update_time";
	public final static String BANNER_INFO_LIST_UPDATE_TIME = "banner_info_list_update_time";
	
	//Mac 주소
	public final static String MAC_ADDRESS = "mac_address";
	
	//app id 주소
	public final static String APP_ID = "app_id";
	
	/**
	 * @brief app id 설정
	 * @param _ctx
	 * @param MacAddress
	 */
	public static void setAppId(Context _ctx, String macAddress){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		SharedPreferences.Editor edit = pref.edit();
		edit.putString(APP_ID, macAddress);
		edit.commit();
	}
	
	/**
	 * @brief app id 읽기
	 * @param _ctx
	 * @return
	 */
	public static String getAppId(Context _ctx){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		return pref.getString(APP_ID, null);
	}
	
	/**
	 * @brief MacAddress 설정
	 * @param _ctx
	 * @param MacAddress
	 */
	public static void setMacAddress(Context _ctx, String macAddress){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		SharedPreferences.Editor edit = pref.edit();
		edit.putString(MAC_ADDRESS, macAddress);
		edit.commit();
	}
	
	/**
	 * @brief MacAddress 읽기
	 * @param _ctx
	 * @return
	 */
	public static String getMacAddress(Context _ctx){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		return pref.getString(MAC_ADDRESS, null);
	}
	
	/**
	 * @brief Store ImageList data timestamp 값 설정
	 * @param _ctx
	 * @return 설정 값 반환
	 */
	public static long getProductListDataTimeStamp(Context _ctx){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		return pref.getLong(PRODUCT_LIST_UPDATE_TIME,-1);
	}
	
	/**
	 * @brief Store ImageList data timestamp 값 읽기
	 * @param _ctx
	 * @param timeStamp 서버 날짜
	 */
	public static void setProductListDataTimeStamp(Context _ctx, long timeStamp){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		SharedPreferences.Editor edit = pref.edit();
		edit.putLong(PRODUCT_LIST_UPDATE_TIME, timeStamp);
		edit.commit();
	}
	
	/**
	 * @brief Store ImageList data timestamp 값 설정
	 * @param _ctx
	 * @return 설정 값 반환
	 */
	public static long getContentInfoListDataTimeStamp(Context _ctx){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		return pref.getLong(CONTENT_INFO_LIST_UPDATE_TIME,-1);
	}
	
	/**
	 * @brief Store ImageList data timestamp 값 읽기
	 * @param _ctx
	 * @param timeStamp 서버 날짜
	 */
	public static void setContentInfoListDataTimeStamp(Context _ctx, long timeStamp){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		SharedPreferences.Editor edit = pref.edit();
		edit.putLong(CONTENT_INFO_LIST_UPDATE_TIME, timeStamp);
		edit.commit();
	}
	
	/**
	 * @brief Store ImageList data timestamp 값 설정
	 * @param _ctx
	 * @return 설정 값 반환
	 */
	public static long getBannerInfoListDataTimeStamp(Context _ctx){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		return pref.getLong(BANNER_INFO_LIST_UPDATE_TIME,-1);
	}
	
	/**
	 * @brief Store ImageList data timestamp 값 읽기
	 * @param _ctx
	 * @param timeStamp 서버 날짜
	 */
	public static void setBannerInfoListDataTimeStamp(Context _ctx, long timeStamp){
		SharedPreferences pref = _ctx.getSharedPreferences(INI_FILENAME_CONFIG, 0);
		SharedPreferences.Editor edit = pref.edit();
		edit.putLong(BANNER_INFO_LIST_UPDATE_TIME, timeStamp);
		edit.commit();
	}
}
